package com.superman.controller;

import com.superman.cache.Cache;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author superman
 * @date 2023/3/3 10:38
 */
@Slf4j
@RestController
@RequestMapping("/free")
@Api(tags = "测试")
public class FreeController {

    @Resource(name = "globalCache")
    private Cache globalCache;


    @GetMapping("/globalCache/setString")
    @ApiOperation(value = "设置缓存")
    public Object globalCacheSetString(@RequestParam String cacheKey,
                                       @RequestParam String cacheValue,
                                       @RequestParam(defaultValue = "31536000") Integer timeout) {
        return globalCache.setCache(cacheKey, cacheValue, timeout, TimeUnit.SECONDS);
    }

    @GetMapping("/globalCache/getObj")
    @ApiOperation(value = "获取obj")
    public Object globalCacheGetObj(@RequestParam String cacheKey) {
        return globalCache.getJavaBeanByCache(cacheKey, Object.class);
    }

    @GetMapping("/globalCache/getList")
    @ApiOperation(value = "获取list")
    public Object globalCacheGetList(@RequestParam String cacheKey) {
        return globalCache.getJavaListByCache(cacheKey, Object.class);
    }


}
